package wusiyuan.dao.impl;

import java.sql.SQLException;
import java.util.List;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import entity.User_Address;
import util.C3P0Util;
import wusiyuan.dao.ShowTheAddressDao;

public class ShowTheAddressDaoImpl implements ShowTheAddressDao {

	@Override
	public List<User_Address> getUserAddressByUserId(Integer i) {
		List<User_Address> list=null;
		QueryRunner qr = new QueryRunner(C3P0Util.getDataSource());	
		String sql = "select * from user_addr where userId = ?";
		try {
			list = qr.query(sql, i, new BeanListHandler<User_Address>(User_Address.class));
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return list;
	}

	@Override
	public User_Address getDefaultAddressByUserId(Integer userId) {
		QueryRunner qr = new QueryRunner(C3P0Util.getDataSource());	
		User_Address ua = null;
		String sql = "select * from user_addr where userId = ? and is_default = 1";
		try {
			ua = qr.query(sql, userId,new BeanHandler<User_Address>(User_Address.class));
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return ua;
	}

}
